export default {
  namespaced: true,
  state: {
    address: uni.getStorageSync('address'),
    token: uni.getStorageSync('token'),
    redirectInfo: null, // 重定向信息
    userInfo: uni.getStorageSync('userInfo') // 用户信息（用于展示个人信息）
  },
  getters: {
    getAddress (state) {
      return state.address
    },
    addstr (state) {
      if (state.address) {
        return `${state.address.provinceName}${state.address.cityName}${state.address.countyName}${state.address.detailInfo}`
      } else {
        return ''
      }
    },
    getToken (state) {
      return state.token
    },
    getRedirectInfo (state) {
      return state.redirectInfo
    },
    getUserInfo (state) {
      return state.userInfo
    }
  },
  mutations: {
    setAddress (state, address) {
      state.address = address
      uni.setStorageSync('address', address)
    },
    setToken (state, token) {
      state.token = token
      uni.setStorageSync('token', token)
    },
    setRedirectInfo (state, redirectInfo) {
      state.token = redirectInfo
    },
    setUserInfo (state, userInfo) {
      state.token = userInfo
      uni.setStorageSync('userInfo', userInfo)
    }
  }
}
